(function () {
    Codestrong.ui.CreateExamDetail= function (_args) {

//var LectureBySubject = function() {
	var aps='';
	var mobilier = [];
	if(Ti.Platform.osname== 'android') {
  		 Titanium.include('../globals.js');
  		 aps='../';
    }
    else {
   		  Titanium.include('globals.js');
    }

	
	
	
	
	
	/////////////////////FUNCTION//////////
	var getTableData_ExamDetail= function(IDDeThi) {
		// alert(IDDeThi)
		var row = null;
		var data = [];
		var param = {        
		  "IDDeThi" : IDDeThi
		 
		};
		var xhr = Titanium.Network.createHTTPClient({
	   
			   onload : function(e) 
			   {
			       Titanium.API.info(this.responseText);
			       
			       //do whatever you want to do with your response
			   
			
					 json = this.responseText;
					 json=json.replace('<string xmlns="http://tempuri.org/">', '');
					 json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
					 json=json.replace('</string>', '');
					 //alert(json)
					 response = JSON.parse(json);
				    //	alert(response.OBJECT.length);
					
			
					 
				 	 for (i = 0; i < response.OBJECT.length; i++) {
							olecture = response.OBJECT[i];
						
						mobilier[i]=olecture;
					   //alert(olecture)
					}
					//lbLoading.text='';
					//Lectureview.setData(data)
					//spCreateListVideoImage(mobilier)
					PopularExam(mobilier)
					Codestrong.ui.activityIndicator.hideModal();
					
			   }, 
	   
			   onerror : function(e) {
			   	 
			       Codestrong.ui.activityIndicator.hideModal();
			   },
			   timeout : Globals.timeout //5000
	    
		});
		xhr.open("POST",Globals.serviceurl_GetExamDetail);
		xhr.send(param);
		
	};
	var PopularExam= function(mobilier) {
		
		if(mobilier.length>0)
		{
			if(mobilier[0].IsDeThiPdf==0)
			{
				//Load de thi word
				//alert(mobilier[0].IsDeThiPdf)
				//data[0].url='http://thaytro.vn/exam_mobile.aspx?cid='+_args.Id
				var data = [
			    	{
			            title: 'Câu hỏi',
			            view: Ti.UI.createWebView({
			               top:0,
			               url:'http://thaytro.vn/exam_mobile.aspx?cid='+_args.Id,
			          //  url : 'http://docs.google.com/viewer?url=http%3A%2F%2Fassets.appcelerator.com.s3.amazonaws.com%2Fdocs%2FAPI_UITableViewClass.pdf'
			             
			            })
			    	},
			    	{
			            title: 'Đáp án',
			            view: Ti.UI.createWebView({
			            	top:0,
			             //   url: 'http://lhs.com.vn/product.html'
			            })
			    	}
			    ];
			    
			    win.add(Codestrong.ui.createTabbedScrollableView({
			    	data:data,
			    	top:main_header.height
			    	})
			    );
			}
			else
			{
				var url_dethi='';
				var url_dapan='';
				if(Ti.Platform.osname== 'android') {
					url_dethi=mobilier[0].file_de_thi_pdf
					url_dapan=mobilier[0].file_de_thi_pdf
				}
				else
				{
					url_dethi=mobilier[0].file_DapAn_pdf_iphone
					url_dapan=mobilier[0].file_DapAn_pdf_iphone
				}	
				//Load de thi pdf
				var data = [
			    	{
			            title: 'Câu hỏi',
			            view: Ti.UI.createWebView({
			               top:0,
			              // url : 'http://docs.google.com/viewer?url=http%3A%2F%2Fassets.appcelerator.com.s3.amazonaws.com%2Fdocs%2FAPI_UITableViewClass.pdf'
			               url : url_dethi//mobilier[0].file_de_thi_pdf
			             
			            })
			    	},
			    	{
			            title: 'Đáp án',
			            view: Ti.UI.createWebView({
			            	top:0,
			          		url : url_dapan//mobilier[0].file_DapAn_pdf
			            })
			    	}
			    ];
			    
			    win.add(Codestrong.ui.createTabbedScrollableView({
			    	data:data,
			    	top:main_header.height
			    	})
			    );
			}
		}
		
	}
	
	
	
	
	var win = Titanium.UI.createWindow({
            id: 'ExamDetail',
           // title: _args.TenMonHoc,//_args.LectureName,
            backgroundColor: '#FFF',
            barColor: '#414444',
            fullscreen: false
    });
    var egc = new globals.EventGarbageCollection(win);

  
   
   
    egc.addEventListener('back_ExamDetail', function () {
 		
    	
 		Codestrong.navGroup.close(win, {
                        animated: true
        });
        
	});
	
	////////////main_header///////////////////////////
	 var databutton_right=[
    	//{Id:1,Image:aps+'images/list_bullets.png',Image_:aps+'images/list_bullets_.png',tag:'Category'},
	    {Id:2,Image:aps+'images/account.png',Image_:aps+'images/account_.png',tag:'Login'},
	    //{Id:3,Image:aps+'images/search.png',Image_:aps+'images/search_.png',tag:'Search'},
	    
	]
	var main_header=require('controls/main_header').main_header({
	 		backgroundImage: aps+'images/panel3.png',
	 		headertext: 'Thầy trò Mobile: '+ _args.TenMonHoc,//_args.LectureName,
		    left: 0,
		    top: 0,
		    height:65,
		    width: Globals.platformWidth,
		    touchEnabled: true		,
		     databutton_right:databutton_right,
		    imback:   aps+'images/back.png',
		    imback_:   aps+'images/back_.png',
		    idWinParent:'ExamDetail',
    })

	win.add(main_header);
	
	
	
	
	
	var ScrollViewMain = Ti.UI.createScrollView({
		top:main_header.top+main_header.height,
		
		touchEnabled:true,
		//height:'100%',
		scrollsToTop:true,
		
	});
	

	
	
    
  
    
	
	
	//win.add(ScrollViewMain);
	/////////////////////////OPEN WINDOWN/////////////////////////
	
	Codestrong.ui.activityIndicator.showModal(Globals.loading, Globals.timeout, Globals.loadingTimeout);
	
	getTableData_ExamDetail(_args.Id)
	
	///////////////////////////////////////////////////////////////
 	return win;
       
    };
})();